/**
 * Created by hongye.liu on 14-10-29.
 * bus软件的主界面
 */
define(['jquery','underscore','backbone','global','./javaPlugin/location','text!/android_asset/busAppWeb/module/busApp/busApp.html'],
        function($,_,Backbone,global,location,html){
            var busAppView = Backbone.View.extend({
                    el:$('#busMain'),
                    template: _.template(html),
                    initialize:function(data){
                        this.el = $('#busMain');
                        this.render();
                        this.initMethod();
                    },

                    render:function(){
                        this.el.html(this.template);
                        $('#busMain').trigger("create");
                        return this;
                    },
                    initCity:function() {
                        var myGeo = new BMap.Geocoder();
                        // 根据坐标得到地址描述
                        myGeo.getLocation(new BMap.Point(global.longitude,global.latitude), function(result){
                            if (result){
                                global.city = result.addressComponents.city;
                                $('#cityText')[0].innerText = global.city;
                            }
                        });

                    },
                    initMethod:function(){
                        $('#baiduMap').height($(window).height());
                        var _this = this;
                        location.callNativePlugin('location','', function (data) {
                            global.longitude=data.Longitude;
                            global.latitude=data.Latitude;
                            _this.initCity();
                        });

                    }
            });
            return busAppView;
        }
)
